<?php

  require_once "JooS/File.php";

  class JooS_File_Xsl extends JooS_File {
    const containerFolder = "jas";

    const jasFolder = ".xsl";

    private $_xslFile = null;

    private $_document = null;

    public function __construct($xslFile) {
      parent::__construct();
      $this->_xslFile = $xslFile;
    }

    public function getDocument() {
      if (is_null($this->_document)) {
        $this->_document = new DOMDocument();

        $filePath = self::containerFolder . DIRECTORY_SEPARATOR . self::jasFolder . DIRECTORY_SEPARATOR . $this->_xslFile;
        $content = self::getContent($filePath);

        if ($content !== false)
          @$this->_document->loadXML($content);

        if (is_null($this->_document->documentElement))
          $this->_document->loadXML(self::getEmptyXsl());
      }
      return $this->_document;
    }

    public function getProcessor() {
      $xsl = new XSLTProcessor();
      @$xsl->importStyleSheet($this->getDocument());

      return $xsl;
    }

    private function getEmptyXsl() {
      return '<?xml version="1.0" encoding="' .ini_get("default_charset"). '"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="@*|node()|comment()|processing-instruction()" />
</xsl:stylesheet>';
    }
    
  }

?>